﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Encrypt;
using Layer;
using IPRMIS_U_Contract;

namespace PremisPublisher.ViewModel
{
    public class StringEncryptViewModel : ViewModelBase
    {

        private string oriString;

        public string OriString
        {
            get { return oriString; }
            set
            {
                oriString = value;
                RaisePropertyChanged("OriString");
            }
        }

        private string newString;

        public string NewString
        {
            get { return newString; }
            set
            {
                newString = value;
                RaisePropertyChanged("NewString");


            }
        }



        private string promptText;

        public string PromptText
        {
            get { return promptText; }
            set
            {
                promptText = value;
                RaisePropertyChanged("PromptText");
            }
        }


        public StringEncryptViewModel()
        {

        }

        /// <summary>
        /// 字符串加密
        /// </summary>
        /// <param name="old_str"></param>
        /// <returns></returns>
        private string __encrypt_string(string old_str)
        {
           //base64 
            return old_str.Encrypt();
            //rsa
            //return PremisPublisher.Common.RSACrypto.Encrypt(old_str, PremisPublisher.Common.crypt_sql_files_reader.GetInstance().GetRSAPublicKey());
        }

        private string __decrypt_string(string old_str)
        {
            return old_str.Decrypt();
        }

        private RelayCommand _encryptCommand;

        public RelayCommand EncryptCommand
        {
            get
            {
                return _encryptCommand ?? (_encryptCommand = new RelayCommand(() =>
                {
                    NewString = __encrypt_string(OriString);
                    PromptText = "";
                }, () => { return !string.IsNullOrEmpty(OriString); }));
            }

        }


        private RelayCommand _copyToClipCommand;

        public RelayCommand CopyToClipCommand
        {
            get
            {
                return _copyToClipCommand ?? (_copyToClipCommand = new RelayCommand(() =>
                {
                    System.Windows.Clipboard.SetText(NewString);
                    PromptText = "已复制到剪贴板";

                }, () => { return !string.IsNullOrEmpty(NewString); }));
            }
        }


        private RelayCommand _decryptCommand;

        public RelayCommand DecryptCommand
        {
            get {
                return _decryptCommand ?? (_decryptCommand = new RelayCommand(() => {
                    OriString = __decrypt_string(NewString);
                }, () => { return !string.IsNullOrEmpty(NewString); }));
            }
        }

    }
}
